Sections

  • Define how your program is organized in memory and in the object file.

  • They tell the assembler and linker where code and data go, and how they should be treated (readable, writable, executable, initialized, etc.).

  • The exact names and behavior depend on the format (ELF on Linux, PE on Windows, Mach-O on macOS), but the core concepts are consistent.

  • Linker may insert padding between sections:

    align 16
    
  • At runtime:

    • Sections in your .asm file become sections in the ELF object file, which the linker groups into segments.

    • .text  â†’ RX memory

    • .data  â†’ RW memory (preloaded)

    • .bss  â†’ RW memory (zeroed)

_start

  • Is not just a convention. It is the default program entry symbol used by the linker (on ELF systems like Linux).

  • When you run a program:

    • Kernel loads the executable

    • Sets up stack (argc, argv, envp)

    • Jumps to the address of _start

  • No C runtime, no setup—just direct execution.

  • Is _start required?

    • By default: yes, linker expects it

    • But you can override: ld -e my_entry file.o .

.text

  • The code section.

  • Contains executable instructions

  • Typically read + execute, not writable

  • Entry point ( _start  or main ) lives here

  • Writing to .text  â†’ crash (NX protection)

.data

  • Initialized data.

  • Stores initialized global/static variables

  • Read + write

  • Values are embedded in the binary

.bss

  • Uninitialized data.

  • “reserve space, don’t store bytes”

  • Space is reserved but not initialized.

  • Read + write

  • Does not take space in the file.

  • Loader initializes it to zero at runtime

Why it exists
  • Efficiency.

  • Instead of:

    big_array times 1000000 db 0
    
  • You write:

    big_array resb 1000000
    
  • Result:

    • File size: small

    • Memory at runtime: same size

    • Loader zeroes it automatically

.rodata

  • Read-only data, prevents accidental modification

  • Constants, strings (in many toolchains)

section .rodata
    pi dq 3.141592653589793
  • Writing to .rodata  â†’ crash (read-only)

.stack

  • Defines stack region.

  • Usually handled by OS, not manually in simple programs.